package org.xhy.beanchameleon.service;

import org.xhy.beanchameleon.annotation.ChameleonX;
import org.xhy.beanchameleon.core.Chameleon;
import org.xhy.beanchameleon.core.ChameleonSrcCode;
import org.xhy.beanchameleon.pipeline.ChainContext;
import org.xhy.beanchameleon.pipeline.ChainProcess;

/**
 * @description: 基于内存管理变色龙
 * @gitee: https://gitee.com/XhyQAQ
 * @copyright: B站: https://space.bilibili.com/152686439
 * @Author: Xhy
 * @CreateTime: 2024-03-24 17:08
 */
public class MemoryChameleonManager extends ChameleonManagerService implements ChainProcess<ChameleonSrcCode> {



    @Override
    public void process(ChainContext<ChameleonSrcCode> context) {
        final ChameleonSrcCode processModel = context.getProcessModel();
        final Chameleon chameleon = processModel.getChameleon();
        final String name = chameleon.getClass().getAnnotation(ChameleonX.class).value();
        try {
            super.register(name,processModel.getJavaSrc(),chameleon);
        }catch (Exception e){
            context.setNeedBreak(true);
            context.setException(e);
        }
    }
}
